<?php

	/**
	* Copyright 2012 - ABSoft Viet Nam
	* @author trungdt
	* @since Apr, 2012
	* @version abs_1.0
	* 
	* This action force template change
	* 
	* Parameters:
	* - force_platform : 
	*       = desktop : desktop based
	*       = mobile : mobile based
	*       = other_type : other type, for example, android, ipad, to specify exactly template
	*/

	if (!defined('EXPONENT')) exit('');

	$test_theme = DISPLAY_THEME;
	if (isset($_REQUEST['force_platform']))
	{
		$template_suff = "";
		$template_suff = $_REQUEST['force_platform'];
		$template_suff = strtolower(preg_replace('/[^A-Za-z0-9_ ]/','',$template_suff));
		if ($template_suff != "dekstop")
		{
			$template_suff="-{$template_suff}";
			// check template exist or not
			if (is_readable(BASE.'themes/'.$test_theme.$template_suff))
				$test_theme=$test_theme.$template_suff;
			else // if not exist, fallback to desktop or mobile theme
			{
				if (!$browser->isMobile())
					$test_theme=DISPLAY_THEME_REAL;
				else
				{
					if (is_readable(BASE.'themes/'.DISPLAY_THEME_REAL."-mobile"))
						$test_theme=DISPLAY_THEME_REAL."-mobile";
					else
						$test_theme=DISPLAY_THEME_REAL;
				}                    
			}
		}
	}
	
	$_SESSION[SYS_SESSION_KEY]['vars']['display_theme_force'] = 1; // force dont change theme
	$_SESSION[SYS_SESSION_KEY]['vars']['display_theme'] = $test_theme;
	
	exponent_flow_redirect();
?>